package com.yyx.pojo;


import com.yyx.mapper.MessageMapper;
import com.yyx.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class testMsg {
    @Test
    public void test() throws IOException {
//        指定配置文件，并读取
        InputStream resource = Resources.getResourceAsStream("mybatis-Config.xml");
//        创建mybatis工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
//       利用工厂对象，获取SqlSession对象
        SqlSession session = sqlSessionFactory.openSession();

//        利用SqlSession对象，获取UserMapper的代理对象
        MessageMapper mapper = session.getMapper(MessageMapper.class);
//        调用UserMapper接口中的方法；在调用方法时，会被代理对象拦截，由代理对象处理要执行的方法
        String msgType = mapper.findMsgType();
        System.out.println(msgType);
    }

}
